package offer.day1;

import java.util.Arrays;

public class No1AssigningOperator {
    public static void main(String[] args) {
        String s = "Change before";   //定义两个字符串
        String s1 = "Change after";
        CMyString cms = new CMyString(s.toCharArray());
        CMyString cms1 = new CMyString(s1.toCharArray());
        System.out.println(cms.toString());
        cms.dengyu(cms1);
        System.out.println(cms.toString());
    }

}

class CMyString {
    private char[] m_pData;

    public CMyString(char[] pData) {      //输入的是字符型
        m_pData = pData;
    }

    public CMyString(CMyString str) {    //输入的是CMyString类的对象
        m_pData = str.m_pData;
    }

    public CMyString dengyu(CMyString str) {
        if (this != str) {
            this.m_pData = null;
            this.m_pData = new char[str.m_pData.length];
            for (int i = 0; i < m_pData.length; i++) {
                m_pData[i] = str.m_pData[i];
            }
        }
        return this;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder("字符串的结果是：");
        for (int i = 0; i < m_pData.length; ++i)
            result.append(m_pData[i]);

        return result.toString();
    }
}
